<?php
namespace app\common\system\validate;


use app\common\system\logic\FormLogic;
use think\Validate;

class PasswordValidate extends Validate
{
    protected $rule = [
        'oldpassword' => ['require'],
        'newpassword' => ['min:6', 'max:12', 'checkPassword'],
        'renewpassword' => ['require','confirm:newpassword']
    ];

    protected $message = [
        'oldpassword' => '原始密码不能为空',
        'newpassword.min' => '密码长度6-12位',
        'newpassword.max' => '密码长度6-12位',
        'renewpassword.require' => '确认密码不能为空',
        'renewpassword.confirm' => '两次输入密码不一致',
    ];

    protected function checkPassword($value, $rule, $data=[])
    {
        $matchCha = preg_match("/.+?([a-zA-Z])/", $value);
        if (!$matchCha) {
            return '密码必须包含字母';
        }

        $matchNum = preg_match("/\d+?/",$value);
        if (!$matchNum) {
            return '密码必须包含数字';
        }

        return true;
    }
}